package com.trkj.controller.lzs;


import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojo.Jobseekersmasterdate;
import com.trkj.pojo.Jobseekersregister;
import com.trkj.pojo.Position;
import com.trkj.pojo.RecruitAdministration;
import com.trkj.pojo.Recruitapply;
import com.trkj.pojo.Recruitplan;
import com.trkj.pojo.Recruitprocess;
import com.trkj.pojo.SocialSecurity;
import com.trkj.service.lzs.RecruitmentService;
import com.trkj.vo.Result;

@Controller
public class RecruitmentController {
	@Autowired
	//招聘
	RecruitmentService ReService;
	 /**
	  * 招聘流程的模板，//Template for Recruitment process,
职位模板的视图，//View of the Position template,
招聘的申请单，//Application form for recruitment,
生成招聘计划的向导，//Generate the guide of Recruitment plan,
招聘的计划，//Recruitment plan,
检查工具，//Inspection tools,
求职人员登记，//Registration of job seekers,
求职人员主要数据，//Main data of job seekers,
招聘管理(人事)，//Recruitment management (personnel),recruit administration
生成员工数据的向导，//A guide to employee data generation,
招聘的辅助资料,//Supplementary information on recruitment,
	  * @param m
	  * @return
	  */
	//1,招聘流程模板
	@GetMapping("hr_rp")
	public String hr_rp(Model m){
		return "recruitment/recruit_process";
	}
	//招聘流程模板全部数据的查询
	@RequestMapping("hr_rp_find")
	@ResponseBody
	public List<Recruitprocess> hr_rp_pRet(){
		return ReService.findAllRe();
	}
	//招聘流程模板的新增
	@RequestMapping("hr_rp_form_add_c")
	@ResponseBody
	public Result hr_rp_add(String reproName, String reproPerson){
		try {
			Recruitprocess re = new Recruitprocess();
			re.setReproName(reproName);
			re.setReproPerson(reproPerson);
			ReService.addRecruitprocess(re);
			return Result.SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Result.failure(e.getMessage());
		}
	}
	//招聘流程模板的编辑；
	@RequestMapping("hr_rp_form_edit_c")
	@ResponseBody
	public Result hr_rp_edit(Long reproId, String reproName, String reproPerson){
		try {
			ReService.editRecruitprocess(reproId,reproName,reproPerson);
			return Result.SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Result.failure(e.getMessage());
		}
	}
	//编辑；通过id查出相应的一条数据
		@RequestMapping("hr_rp_find_load")
		@ResponseBody
	public Recruitprocess hr_rp_load(Long reproId){
			return ReService.findAllReLoad(reproId);
	}
		//删除；通过id查出相应的一条数据
		@RequestMapping("hr_rp_form_dlt")
		@ResponseBody
		public boolean hr_rp_form_dlt(Long reproId){
			 return ReService.dltRe(reproId);
	}
			
		//模糊查询shuoy
		@RequestMapping("lzs_Recruitprocesschaxun")
		@ResponseBody
		public  List<Recruitprocess> Query(String text){
	
			return (List<Recruitprocess>) ReService.queryByName(text);
		}
			
			
			
			
			
			

			
		//2,招聘申请单
	@GetMapping("hr_ra")
	public String hr_ra(Model m){
		return "recruitment/recruit_apply";
	}
	//招聘申请单全部数据的查询
	@RequestMapping("hr_ra_find")
	@ResponseBody
	public List<Recruitapply> hr_ra_pRet(){
		return ReService.findAllRa();
	}
	//招聘申请单的新增
	@RequestMapping("hr_ra_form_add_c")
	@ResponseBody
	public Result hr_ra_add(String reappExplain, BigDecimal reappPlan){
		try {
				Recruitapply re = new Recruitapply();
				Date date = new Date();
				re.setReappExplain(reappExplain);
				re.setReappPlan(reappPlan);
				re.setReappDemanddate(new Timestamp(date.getTime()));
				ReService.addRecruitapply(re);
				return Result.SUCCESS;
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return Result.failure(e.getMessage());
			}
		}
	//招聘申请单的编辑；
		@RequestMapping("hr_ra_form_edit_c")
		@ResponseBody
		public Result hr_ra_edit(Long reappId, String reappExplain, BigDecimal reappPlan){
			try {
					ReService.editRecruitapply(reappId,reappExplain,reappPlan);
					return Result.SUCCESS;
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return Result.failure(e.getMessage());
				}
			}
		//编辑；通过id查出相应的一条数据
		@RequestMapping("hr_ra_find_load")
		@ResponseBody
		public Recruitapply hr_ra_load(Long reappId){
				return ReService.findAllRaLoad(reappId);
		}
		//删除；通过id查出相应的一条数据
		@RequestMapping("hr_ra_form_dlt")
		@ResponseBody
		public boolean hr_ra_form_dlt(Long reappId){
			 return ReService.dltRa(reappId);
		}
		//模糊查询shuoy
		@RequestMapping("lzs_Recruitapplychaxun")
		@ResponseBody
		public  List<Recruitapply> reappQuery(String text){
	
			return (List<Recruitapply>) ReService.RecruitapplyqueryByName(text);
		}
					
					
					
					
					
		//3,招聘计划
		@GetMapping("hr_rplan")
		public String hr_rplan(Model m){
			return "recruitment/recruit_plan";
		}
		@GetMapping("hr_rplan_add")
		public String recruit_plan_add(Model m){
			return "recruitment/recruit_plan_add";
		}
		//招聘计划全部数据的查询
		@RequestMapping("hr_rplan_find")
		@ResponseBody
		public List<Recruitplan> hr_rplan_pRet(){
			return ReService.findAllrplan();
		}
		//招聘计划的新增
		@RequestMapping("hr_rplan_form_add_c")
		@ResponseBody
		public Result hr_rplan_add(Recruitplan re){
			try {
				/*Recruitplan re = new Recruitplan();*/
					Date date = new Date();
					ReService.addrplan(re);
					return Result.SUCCESS;
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return Result.failure(e.getMessage());
				}
		}
		            //招聘计划的编辑；
						@RequestMapping("hr_rplan_form_edit_c")
						@ResponseBody
						public Result hr_rplan_edit(Long recplanId, String reappExplain, BigDecimal reappPlan){
							try {
								ReService.editRecruitapply(recplanId,reappExplain,reappPlan);
								return Result.SUCCESS;
							} catch (Exception e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
								return Result.failure(e.getMessage());
							}
						}
						//编辑；通过id查出相应的一条数据
							@RequestMapping("hr_rplan_find_load")
							@ResponseBody
						public Recruitplan hr_rplan_load(Long recplanId){
								return ReService.findAllrplanLoad(recplanId);
						}
							//删除；通过id查出相应的一条数据
							@RequestMapping("hr_rplan_form_dlt")
							@ResponseBody
							public boolean hr_rplan_form_dlt(Long recplanId){
								 return ReService.dltrplan(recplanId);
								}
							
							
							
							//4,求职人员主数据
							@GetMapping("hr_jsmd")
							public String hr_jsmd(Model m){
								return "recruitment/MainDataOfJobSeekers";
							}
							@GetMapping("hr_jsmd_info")
							public String hr_jsmd_info(Model m,Long jsmdId){
								Jobseekersmasterdate js  = ReService.findAlljsmdLoad(jsmdId);
								m.addAttribute("js", js);
								return "recruitment/mainDataOfJobSeekers_info";
							}
							@GetMapping("hr_jsmd_add")
							public String recruit_jsmd_add(Model m){
								return "recruitment/MainDataOfJobSeekers_add";
							}
							//求职人员主数据全部数据的查询
								@RequestMapping("hr_jsmd_find")
								@ResponseBody
								public List<Jobseekersmasterdate> hr_jsmd_pRet(){
									return ReService.findAlljsmd();
								}
								//求职人员主数据的新增
								@RequestMapping("hr_jsmd_form_add_c")
								@ResponseBody
								public Result hr_jsmd_add(Jobseekersmasterdate re){
									try {
										/*Recruitplan re = new Recruitplan();*/
										Date date = new Date();
										
										ReService.addjsmd(re);
										return Result.SUCCESS;
									} catch (Exception e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
										return Result.failure(e.getMessage());
									}
								}
								//求职人员主数据的编辑；
								@RequestMapping("hr_jsmd_form_edit_c")
								@ResponseBody
								public Result hr_jsmd_edit(Jobseekersmasterdate js){
									try {
										ReService.editjsmd(js);
										return Result.SUCCESS;
									} catch (Exception e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
										return Result.failure(e.getMessage());
									}
								}
								//编辑；通过id查出相应的一条数据
									@RequestMapping("hr_jsmd_find_load")
									@ResponseBody
								public Jobseekersmasterdate hr_jsmd_load(Long recplanId){
										return ReService.findAlljsmdLoad(recplanId);
								}
									//删除；通过id查出相应的一条数据
									@RequestMapping("hr_jsmd_form_dlt")
									@ResponseBody
									public boolean hr_jsmd_form_dlt(Long recplanId){
										 return ReService.dltjsmd(recplanId);
										}
									
									//模糊查询shuoy
									@RequestMapping("lzs_Jobseekersmasterdatechaxun")
									@ResponseBody
									public  List<Jobseekersmasterdate> JobQuery(String text){
									       System.out.println(text);
										return (List<Jobseekersmasterdate>) ReService.JobseekersmasterdatequeryByName(text);
									}  
																
									
									
									
				//5,求职人员登记
				@GetMapping("hr_jsr")
				public String hr_jsr(Model m){
					return "recruitment/Jobseekersregister";
				}
				@GetMapping("hr_jsr_add")
				public String recruit_jsr_add(Model m){
					return "recruitment/Jobseekersregister_add";
				}
				@GetMapping("hr_jsr_info")
				public String recruit_jsr_info(Model m,Long jsrId,Long positionId,Long recplanId){
						Jobseekersregister job = ReService.findAlljsrLoad(jsrId);
						Recruitplan jobRecplan = ReService.findAllrplanLoad(recplanId);
						Position jobPosition = ReService.findPositionIdLoad(positionId);
						m.addAttribute("job", job);
						m.addAttribute("jobPosition", jobPosition);
						m.addAttribute("jobRecplan", jobRecplan);
						return "recruitment/Jobseekersregister_info";
				}
				//求职人员登记的全部数据的查询
				@RequestMapping("hr_jsr_find")
				@ResponseBody
				public List<Jobseekersregister> hr_jsr_pRet(){
					return ReService.findAlljsr();
				}
				//求职人员登记中的招聘计划的查询
				@RequestMapping("hr_jsr_find_recruitplan_Reverse")
				@ResponseBody
				public List<Recruitplan> hr_jsr_find_recruitplan_Reverse(){
					return ReService.findAllrplan();
				}	
				//求职人员登记中的招聘计划的查询
				@RequestMapping("hr_jsr_find_position_Reverse")
				@ResponseBody
				public List<Position> hr_jsr_find_position_Reverse(){
					return ReService.findAllPosition();
				}	
				//求职人员登记的新增
				@RequestMapping("hr_jsr_form_add_c")
				@ResponseBody
				public Result hr_jsr_add(Jobseekersregister re,Long recplanId1,Long positionId1){
				try {
						/*Recruitplan re = new Recruitplan();*/
						Date date = new Date();
						ReService.addjsr(re,recplanId1,positionId1);
						return Result.SUCCESS;
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
						return Result.failure(e.getMessage());
					}
				}
				//求职人员登记的编辑；
				@RequestMapping("hr_jsr_form_edit_c")
				@ResponseBody
				public Result hr_jsr_edit(Jobseekersregister re,Long recplanId1,Long positionId1){
					try {
						ReService.editjsr(re,recplanId1,positionId1);
						return Result.SUCCESS;
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
						return Result.failure(e.getMessage());
					}
				}
				//编辑；通过id查出相应的一条数据
	@RequestMapping("hr_jsr_find_load")
	@ResponseBody
	public Jobseekersregister hr_jsr_load(Long recplanId){
			return ReService.findAlljsrLoad(recplanId);
	}
	//删除；通过id删除相应的一条数据
	@RequestMapping("hr_jsr_form_dlt")
	@ResponseBody
	public boolean hr_jsr_form_dlt(Long jsrId){
		 return ReService.dltjsr(jsrId);
	}
											
											
											
	//模糊查询shuoy
	@RequestMapping("lzs_Jobseekersregisterchaxun")
	@ResponseBody
	public  List<Jobseekersregister> jsrQuery(String text){

		return (List<Jobseekersregister>) ReService.Jobseekersregistercx(text);
	}
										
											
	
	
	
	
	//4,招聘管理
	@GetMapping("hr_radm")
	public String hr_radmin(Model m){
		return "recruitment/recruit_administration";
	}
	@GetMapping("hr_radm_add")
	public String recruit_radm_add(Model m){
		return "recruitment/RecruitAdministration_add";
	}
	@GetMapping("hr_radm_info")
	public String recruit_radm_info(Model m,Long radmId,Long positionId,Long radmId1){
			RecruitAdministration job = ReService.findAllradmLoad(radmId);
			Recruitplan jobRecplan = ReService.findAllrplanLoad(radmId);
			Position jobPosition = ReService.findPositionIdLoad(positionId);
			m.addAttribute("job", job);
			m.addAttribute("jobPosition", jobPosition);
			m.addAttribute("jobRecplan", jobRecplan);
			return "recruitment/RecruitAdministration_info";
	}
	//求职人员登记的全部数据的查询
	@RequestMapping("hr_radm_find")
	@ResponseBody
	public List<RecruitAdministration> hr_radm_pRet(){
		return ReService.findAllradm();
	}
	//求职人员登记中的招聘计划的查询
	@RequestMapping("hr_radm_find_recruitplan_Reverse")
	@ResponseBody
	public List<Recruitplan> hr_radm_find_recruitplan_Reverse(){
		return ReService.findAllrplan();
	}	
	//求职人员登记中的招聘计划的查询
	@RequestMapping("hr_radm_find_position_Reverse")
	@ResponseBody
	public List<Position> hr_radm_find_position_Reverse(){
		return ReService.findAllPosition();
	}	
	//求职人员登记的新增
	@RequestMapping("hr_radm_form_add_c")
	@ResponseBody
	public Result hr_radm_add(RecruitAdministration re,Long radmId1,Long PositionId1){
	try {
			/*Recruitplan re = new Recruitplan();*/
			Date date = new Date();
			ReService.addradm(re,radmId1,radmId1);
			return Result.SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Result.failure(e.getMessage());
		}
	}
	//求职人员登记的编辑；
	@RequestMapping("hr_radm_form_edit_c")
	@ResponseBody
	public Result hr_radm_edit(RecruitAdministration re,Long radmId1,Long positionId1){
		try {
			ReService.editradm(re,radmId1,positionId1);
			return Result.SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Result.failure(e.getMessage());
		}
	}
	//编辑；通过id查出相应的一条数据
	@RequestMapping("hr_radm_find_load")
	@ResponseBody
	public RecruitAdministration hr_radm_load(Long radmId){
	return ReService.findAllradmLoad(radmId);
	}
	//删除；通过id删除相应的一条数据
	@RequestMapping("hr_radm_form_dlt")
	@ResponseBody
	public Result hr_radm_form_dlt(Long readmiId){
		try {
			ReService.dltradm(readmiId);
			return Result.SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Result.failure(e.getMessage());
		}
	}
}
